package com.ts.api.module.match.plan.internal.distribute.model;

import com.ts.api.common.constant.product.ProductPlanTypeEnum;
import com.ts.api.module.match.plan.model.AbstractPlanMatch;
import com.ts.api.module.product.entity.po.ProductApplyFlowPO;
import com.ts.api.module.product.entity.po.ProductPO;
import com.ts.api.module.product.entity.po.ProductPlanPO;
import lombok.Data;

/**
 *  计划分发实体类
 *
 *  @author Pan
 */
@Data
public class PlanDistribute {

    /** 当前请求id */
    private String reqId;
    /** 渠道匹配实体 */
    private AbstractPlanMatch abstractPlanMatch;
    /** 分发主体 */
    private ProductPO productPO;
    /** 分发计划 */
    private ProductPlanPO productPlanPO;
    /** 用户数据请求对象 */
    private PlanDistributeUserRequest planDistributeUserRequest;
    /** 当前流程日志对象 */
    private ProductApplyFlowPO currentDistributeFlow;
    /** 当前计划类型枚举*/
    private ProductPlanTypeEnum planTypeEnum;

    /**
     *  构建分发实体
     *
     *  @param  abstractPlanMatch               当前渠道实体
     *  @param  productPO                       主体实体
     *  @param  distributePlan                  主体计划实体
     *  @param  planDistributeUserRequest       请求用户对象
     *  @param  startDistributeFlow             起始日志
     *  @param  reqId                           请求id
     *  @return PlanDistribute
     */
    public static PlanDistribute of(AbstractPlanMatch abstractPlanMatch, ProductPO productPO, ProductPlanPO distributePlan, PlanDistributeUserRequest planDistributeUserRequest,
                          ProductApplyFlowPO startDistributeFlow, String reqId) {

        PlanDistribute planDistribute = new PlanDistribute();
        planDistribute.setAbstractPlanMatch(abstractPlanMatch);
        planDistribute.setProductPO(productPO);
        planDistribute.setProductPlanPO(distributePlan);
        planDistribute.setPlanDistributeUserRequest(planDistributeUserRequest);
        planDistribute.setCurrentDistributeFlow(startDistributeFlow);
        planDistribute.setReqId(reqId);

        //  获取当前计划类型
        Integer planType = planDistribute.getProductPlanPO().getPlanType();
        planDistribute.setPlanTypeEnum(ProductPlanTypeEnum.getEnum(planType));
        return planDistribute;
    }
}
